<?

//require_once(dirname(__FILE__) . '/../abstract/auth.php');

class bf_auth_db extends bf_auth {

	private $db;
	private $user;

	public function __construct($db, $options = array()) {
		parent::__construct($options);
		$this->db = $db;
		$this->opts = array_merge(array(
			'sql' => 'select password from users where username = $1 and realm = $2 limit 1',
		), $this->opts);
	}

	protected function get_password($username, $realm) {
		$this->user = $this->db->query_row($this->opts['sql'], array($username, $realm));
		return ($this->user ? $this->user['password'] : false);
	}

	public function get_value($name) {
		$value = parent::get_value($name);
		if ($value === null)
			$value = ($this->user ? @$this->user[$name] : null);
		return $value;
	}
}

?>